//
//  HTextViewCell.m
//  Textfield
//
//  Created by 朱同海 on 16/7/6.
//  Copyright © 2016年 朱同海. All rights reserved.
//

#import "HTextViewCell.h"
#import "UITextField+IndexPath.h"
NSString *const HTextViewCellID = @"HTextViewCellID";
@interface HTextViewCell ()<UITextFieldDelegate>
@end

@implementation HTextViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.isEditing = NO;
        [self.contentView addSubview:self.textField];
        [self.contentView addSubview:self.titleLabel];
        
        [self setFrame];
    }
    return self;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (self.isEditing) {
        return YES;
    }
    return NO;
}
- (void)setTitleString:(NSString *)string andDataString:(NSString *)dataString andIndexPath:(NSIndexPath *)indexPath{
    // 核心代码
    self.textField.indexPath = indexPath;
    self.textField.text = dataString;
    self.titleLabel.text = string;
}
- (void)setTitleString:(NSString *)string andDataString:(NSString *)dataString andPlaceholder:(NSString *)placeholder andIndexPath:(NSIndexPath *)indexPath{
    // 核心代码
    self.textField.placeholder = placeholder;
    self.textField.indexPath = indexPath;
    self.textField.text = dataString;
    self.titleLabel.text = string;
}
- (void)setFrame{
    
    CGFloat width = [NSString widthForString:@"任务标题" fontSize:16 andHeight:16];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(width);
    }];
    
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_right).offset(15);
        make.top.bottom.mas_equalTo(0);
        make.right.mas_equalTo(-15);
    }];
}

- (UITextField *)textField{
    if (!_textField) {
        _textField = [[UITextField alloc] init];
        _textField.font = FONT(15);
        _textField.textColor = kUIColorFromRGB(0x333333);
        _textField.delegate = self;
    }
    return _textField;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = FONT(15);
        _titleLabel.textColor = kUIColorFromRGB(0x333333);
    }
    return _titleLabel;
}


@end
